ubuntu源码安装pytorch

您所在的位置:网站首页 asmjit 源代码 ubuntu源码安装pytorch

ubuntu源码安装pytorch

2024-06-26 08:48| 来源: 网络整理| 查看: 265

由于最近学习pytorch需要使用源码的pytorch(貌似是因为包含更多的扩展包?)因此记录一下安装与踩坑过程。 首先整体流程按照官方来: https://github.com/pytorch/pytorch#from-source 我自己用的ubuntu所以按照其中linux的命令进行的安装,下面是过程,其他系统还请按照官方来。

首先

安装cuda与cudnn,注意版本与自己的驱动版本对应,且: NVIDIA CUDA 9.2或以上 NVIDIA cuDNN v7 或以上

1.Install Dependencies:安装依赖 conda install -c pytorch magma-cuda110

注意最后那三个数是自己的cuda版本,我是10.0所以填的100

2.Get the PyTorch Source:获取源码 git clone --recursive https://github.com/pytorch/pytorch cd pytorch # if you are updating an existing checkout git submodule sync git submodule update --init --recursive

注意由于网络问题,一般会有一部分失败的包没下下来,这时在终端一直运行:

git submodule update --init --recursive

直到再次运行这行代码终端没有任何输出,就代表基本都下载完了。

3.Install PyTorch:安装Pytorch

安装代码:

export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} python setup.py install

可能会出现问题: 1.

Building wheel torch-1.9.0a0+git1416e57 -- Building version 1.9.0a0+git1416e57 Could not find any of CMakeLists.txt, Makefile, setup.py, LICENSE, LICENSE.txt in /home/su/pytorch/third_party/tensorpipe

这一般是文件夹下载下来了,里面的内容没下载下来(一个空文件夹),这个时候删掉最后那个目录代表的文件夹,比方说这里是进入/home/su/pytorch/third_party,然后删掉tensorpipe文件夹,然后运行:

git submodule update --init --recursive

文件夹就会重新下载下来(当然如果网络问题又没下载好就多来几遍这个代码),里面的内容也有了,此时再重新运行安装代码即可。

2.

ModuleNotFoundError: No module named 'yaml'

这类一般会在最底下给提示,当然也可能没有。提示如下

Please install it via `conda install pyyaml` or `pip install pyyaml`

照着提示用conda或pip安装对应的包就行。 我遇到的: 有提示:yaml 没提示:typing_extensions,dataclasses

3.

Building wheel torch-1.9.0a0+git1416e57 -- Building version 1.9.0a0+git1416e57 cmake --build . --target install --config Release -- -j 8 make: *** No rule to make target 'install'. Stop.

这种应该是之前使用过一次安装代码,解决方法为将pytorch文件夹下的build文件夹删掉,再重新使用安装代码即可。

4. 这个不确定咋回事,先放这里: 编译安装完后虚拟环境打开python,import torch提示缺包导入失败, 此后重启电脑之后再次进入环境导入直接成功



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3